<template>
        <el-container class="container">
            <el-header>
                <!--  左边   -->
                <div class="left_box">
                    <img src="../assets/img/timg.gif">
                    <span>图书管理</span>
                </div>
                <!--  右边   -->
                <div class="right_box">
                    <!--  下拉框  -->
                    <el-dropdown>
                    <img src="../assets/img/3.jpg">
                        <el-dropdown-menu slot="dropdown">
                            <el-dropdown-item icon="el-icon-user" @click.native="getUser">个人信息</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-house" @click.native="go">系统首页</el-dropdown-item>
                            <el-dropdown-item icon="el-icon-switch-button" @click.native="logout">退出</el-dropdown-item>
                        </el-dropdown-menu>
                    </el-dropdown>


                </div>
            </el-header>
            <el-container>
                <el-aside :width="isshen?'64px':'200px'">
                    <div @click="toggle" class="toggle-button">|||</div>
                    <!--   主菜单       -->
                    <!--    :collapse="isshen"控制伸缩
                            :collapse-transition="false"不产生动画
                            :router="true"让页面以id形式跳转
                     -->
                    <el-menu
                            default-active="2"
                            class="el-menu-vertical-demo"
                            background-color="#001529"
                            text-color="#fff"
                            active-text-color="#ffd04b"
                            :collapse="isshen"
                            :collapse-transition="false"
                            unique-opened
                            :router="true">
                        <!--   子菜单       -->
                        <el-submenu :index="item.id+''" v-for="item in MenuList" :key="item.id+''">
                            <template slot="title">
                                <i :class="item.icon"></i>
                                <span>{{item.menuName}}</span>
                            </template>
                            <!--   子菜单的菜单项       -->
                            <el-menu-item :index="citem.url" v-for="citem in item.children">
                                <template slot="title">
                                    <i :class="citem.icon"></i>
                                    <span>{{citem.menuName}}</span>
                                </template>
                            </el-menu-item>
                        </el-submenu>
                    </el-menu>
                </el-aside>
                <el-main>
                    <router-view></router-view>
                </el-main>
            </el-container>
        </el-container>
</template>

<script>
    export default {
        data() {
            return {
                isCollapse: true,
                isshen:false,
                username:'',
                MenuList:[
                    {
                        "id": 1,
                        "menuName": "系统管理",
                        "icon": "el-icon-setting",
                    },
                    {
                        "id": 2,
                        "menuName": "用户管理",
                        "icon": "el-icon-user",
                        "url": "/users",
                        children: [
                            {
                                "id": 201,
                                "parentId": 2,
                                "menuName": "个人信息",
                                "url": "/user",
                                "icon": "el-icon-user",
                            },
                            {
                                "id": 202,
                                "parentId": 2,
                                "menuName": "修改密码",
                                "url": "/change_pwd",
                                "icon": "el-icon-s-grid",
                            },
                        ]
                    },
                    {
                        "id": 3,
                        "menuName": "图书管理",
                        "icon": "el-icon-reading",
                        "url":'/book',
                        children:[
                            {
                                "id": 301,
                                "parentId": 3,
                                "menuName": "所有图书",
                                "url": "/books",
                                "icon": "el-icon-collection",
                            },
                            {
                                "id": 302,
                                "parentId": 3,
                                "menuName": "图书类型管理",
                                "url": "/booktype",
                                "icon": "el-icon-collection",
                            },
                            {
                                "id": 303,
                                "parentId": 3,
                                "menuName": "图书书室管理",
                                "url": "/bookroom",
                                "icon": "el-icon-office-building",
                            },
                        ]
                    }
                ],
            };
        },
        methods: {
            //控制侧边栏伸缩的方法
            toggle(){
                this.isshen=!this.isshen;
            },
            //安全退出
            logout(){
                //清除session
                window.sessionStorage.clear();
                //页面跳转
                this.$router.push("/login")
            },
           //获取用户信息
            getUser(){
                this.$router.push("/user");
            },
            go(){
                this.$router.push("/welcome")
            }


        }
    }
</script>

<style scoped lang="less">
    //整体格式
    .container{
        height: 100%;
    }
    //头部格式
    .el-header{
        background-color: #001529;
        display: flex;
        justify-content: space-between;
        align-items: center;
        color: #FFFFFF;
        align-items: center;
        font-size: 20px;
        /*  左半边样式*/
        .left_box{
            display: flex;
            align-items: center;

            img{
                height: 60px;
                width: 80px;
                margin: 0px 0px 10px 15px;
            }
            span{
                margin-left: 15px;
            }
        }
        /*  右半边样式*/
        .right_box{
            img{
                height: 60px;
                width: 60px;
                border-radius: 50%;
                background-color: #FFFFFF;
            }
        }

    }
    //侧边栏的样式
    .el-aside {
        background-color: #001529;
        //去掉边框
        .el-menu{
            border-right: none;
        }
        //张开、折叠样式
        .toggle-button{
            background-color: chartreuse;
            font-size: 10px;
            line-height: 24px;
            color:#fff;
            text-align: center;
            letter-spacing: 0.2em;
            cursor: pointer;// 显示鼠标指针为：小手
        }
    }

    .el-main {
        background-color: #E9EEF3;
    }

</style>
